<?php

namespace app\api\controller;

use app\common\model\Attachment as AttachmentModel;
use app\model\Link as LinkModel;
use think\Db;
use think\facade\Log;
use think\facade\Request;

/**
 * @title   广告接口
 * @desc    广告接口
 * Class Link
 * @package app\api\controller
 */

class Link extends Common
{
    /**
     * @title 广告接口
     * @desc  广告接口
     *
     * @param int $title
     * @param int $limit 10
     *
     * @return Array $list 广告接口
     */
    public function banner()
    {
        // try {
        //     $msg = $this->Auth();
        //     if (!$msg) {
        $gname = $this->request->param('gname');
        $limit = $this->request->param('limit');
        if ($gname != '') {
            $map[] = ['group_name', '=', $gname];
        }
        if (!$limit) {
            $limit = 10;
        }
        $list = LinkModel::where($map)
            ->field(['id', 'title', 'url', 'content', 'picture'])
            ->order('id desc')
            ->paginate($limit);

        foreach ($list as $gq) {
            $Attachment = AttachmentModel::get($gq['picture']);
            $gq['picture'] = $this->getPicPath($Attachment['path']);
        }

        return $this->jsonPage($list->total(), $list->toArray()['data']);

    }

}
